//-
// ==========================================================================
// Copyright (C) 2005 ATI Technologies Inc. All rights reserved.
//
// Copyright (C) 1995 - 2006 Autodesk, Inc. and/or its licensors.  All 
// rights reserved.
//
// The coded instructions, statements, computer programs, and/or related 
// material (collectively the "Data") in these files contain unpublished 
// information proprietary to Autodesk, Inc. ("Autodesk") and/or its 
// licensors, which is protected by U.S. and Canadian federal copyright 
// law and by international treaties.
//
// The Data is provided for use exclusively by You. You have the right 
// to use, modify, and incorporate this Data into other products for 
// purposes authorized by the Autodesk software license agreement, 
// without fee.
//
// The copyright notices in the Software and this entire statement, 
// including the above license grant, this restriction and the 
// following disclaimer, must be included in all copies of the 
// Software, in whole or in part, and all derivative works of 
// the Software, unless such copies or derivative works are solely 
// in the form of machine-executable object code generated by a 
// source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. 
// AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED 
// WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF 
// NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR 
// PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE, OR 
// TRADE PRACTICE. IN NO EVENT WILL AUTODESK AND/OR ITS LICENSORS 
// BE LIABLE FOR ANY LOST REVENUES, DATA, OR PROFITS, OR SPECIAL, 
// DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK 
// AND/OR ITS LICENSORS HAS BEEN ADVISED OF THE POSSIBILITY 
// OR PROBABILITY OF SUCH DAMAGES.
//
// ==========================================================================
//+

//
//
// fxManagerCmd.cpp
//
//  This file provides the implementation for the effectManager command.
// This command is useful for querying additional information from the
// shader. Presently, it only supportes listing of the shader text to 
// aid in debugging.
//
////////////////////////////////////////////////////////////////////////////////////////////////////

#include <maya/MArgDatabase.h>
#include <maya/MGlobal.h>

#include "fxManagerCmd.h"

//
// fxManagerCmd::doIt
//
//  This is the function used to invoke the command. The
// command is not undoable and it does not change any state,
// so it does not use the method to call back throught redoIt.
//////////////////////////////////////////////////////////////////////
MStatus fxManagerCmd::doIt( const MArgList &args) {
  MArgDatabase argData( syntax(), args);
  MString nodeName;
  glslShaderNode *node = NULL;

  //check to see if we have a node
  if (argData.isFlagSet( "-n")) {
    argData.getFlagArgument( "-n", 0, nodeName);
    node = glslShaderNode::findNodeByName(nodeName);
    if (!node) {
      MGlobal::displayError( MString("Node '") +nodeName +"' does not exist");
      return MStatus::kFailure;
    }
  }

  //check if we are in list shader mode
  if (argData.isFlagSet( "-ls")) {
    int pass;
    //are we listing a vertex shader
    if (argData.isFlagSet( "-vs")) {
      argData.getFlagArgument( "-vs", 0, pass);
      if (!node->printVertexShader(pass)) {
        MGlobal::displayError( MString("No vertex shader available for pass ") + pass);
        return MStatus::kFailure;
      }
    }
    //are we listing a vertex shader
    if (argData.isFlagSet( "-ps")) {
      argData.getFlagArgument( "-ps", 0, pass);
      if (!node->printPixelShader(pass)) {
        MGlobal::displayError( MString("No pixel shader available for pass ") + pass);
        return MStatus::kFailure;
      }
    }
  }
  

  return MStatus::kSuccess;
}

//
//  There is never anything to undo.
//////////////////////////////////////////////////////////////////////
MStatus fxManagerCmd::undoIt(){
  return MStatus::kSuccess;
}

//
//  There is never really anything to redo.
//////////////////////////////////////////////////////////////////////
MStatus fxManagerCmd::redoIt(){
  return MStatus::kSuccess;
}

//
//
//////////////////////////////////////////////////////////////////////
bool fxManagerCmd::isUndoable() const{
  return false;
}

//
//
//////////////////////////////////////////////////////////////////////
bool fxManagerCmd::hasSyntax() const {
  return true;
}

//
//
//////////////////////////////////////////////////////////////////////
MSyntax fxManagerCmd::mySyntax() {
  MSyntax syntax;

  syntax.addFlag( "-ls", "-listShader");
  syntax.addFlag( "-ps", "-pixelShader", MSyntax::kLong);
  syntax.addFlag( "-vs", "-vertexShader", MSyntax::kLong);
  syntax.addFlag( "-n", "-node", MSyntax::kString);

  return syntax;
}

//
//
//////////////////////////////////////////////////////////////////////
bool fxManagerCmd::isHistoryOn() const {
  //what is this supposed to do?
  return false;
}

//
//
//////////////////////////////////////////////////////////////////////
MString fxManagerCmd::commandString() const {
  return MString();
}

//
//
//////////////////////////////////////////////////////////////////////
MStatus fxManagerCmd::setHistoryOn( bool state ){
  //ignore it for now
  return MStatus::kSuccess;
}

//
//
//////////////////////////////////////////////////////////////////////
MStatus fxManagerCmd::setCommandString( const MString &str) {
  //ignore it for now
  return MStatus::kSuccess;
}

